package cn.lanqiao.demo.dao;

import cn.lanqiao.demo.entity.Leave;
import org.apache.ibatis.annotations.*;

import java.util.List;

/*
* 学生请假类
* */
public interface LeaveDao {

    /*学生添加请假条到数据库*/
    @Insert("INSERT  into  `leave` (Sname,reason,time,place,status,Sno) VALUES (#{Sname},#{reason},#{time},#{place},#{status},#{Sno})")
    public int addLeave(@Param("Sname") String Sname, @Param("reason") String reason,  @Param("time") String time,@Param("place") String place, @Param("status") String status,@Param("Sno") String Sno) throws Exception;

    /*学生请假条信息展示*/
    @Select("SELECT * FROM `leave` WHERE Sno=#{Sno}")
    public List<Leave> showLeaveBySno(String Sno) throws Exception;



    /*学生修改请假条*/
    @Update("UPDATE `leave` set reason=#{reason},time=#{time},place=#{place} WHERE Sno=#{Sno}")
    public int updateLeaveBySno(@Param("reason") String reason,@Param("time") String time,@Param("place") String place,@Param("Sno") String Sno) throws Exception;

    /*学生删除请假条*/
    @Delete("DELETE FROM `leave` WHERE Lno=#{Lno}")
    public int delete(int Lno) throws Exception;

    /*查询所有学生假条*/
    @Select("SELECT * from `leave`")
    public List<Leave> showAll() throws Exception;

    /*查询所有 未批阅 的学生假条，status=0的*/
    @Select("SELECT * from `leave` WHERE `status`=0")
    public List<Leave> notCheck() throws Exception;

    /*老师不同意学生请假，status从0变成1*/
    @Update("UPDATE `leave` SET `status`=1 WHERE Lno=#{Lno}")
    public int unallowLeave(int Lno) throws Exception;

    /*老师同意学生请假，status从1变成2*/
    @Update("UPDATE `leave` SET `status`=2 WHERE Lno=#{Lno}")
    public int allowLeave(int Lno) throws Exception;
}
